home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-11 | 7.7 KB | 325 lines | [TEXT/MPS ] |
- /*
- File: CappuccinoClipboard.cpp
-
- Contents: Implements cut, copy, paste, and clear support.
-
- Written by: Troy Gaul
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- // -- Compiler/Preprocessor Switches --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (eg. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with the "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- Cappuccino Includes --
-
- #ifndef _CAPPUCCINO_
- #include "Cappuccino.h"
- #endif
-
- #ifndef _CAPPUCCINOACTION_
- #include "CappuccinoAction.h"
- #endif
-
- #ifndef _CAPPUCCINOCONTENT_
- #include "CappuccinoContent.h"
- #endif
-
- #ifndef _CAPPUCCINODEF_
- #include "CappuccinoDef.h"
- #endif
-
- #ifndef _CAPPUCCINOGLOBALS_
- #include "CappuccinoGlobals.h"
- #endif
-
- #ifndef _TEMPFOCUS_
- #include "TempFocus.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_ODMenuBar_xh
- #include <MenuBar.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include <ODDebug.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
-
- //------------------------------------------------------------------------------
- // Method: IsClipboardComandEnabled
- // Origin: Cappuccino
- //
- // Description: This method is called by AdjustMenus to determine if an Edit
- // menu command is enabled.
- //------------------------------------------------------------------------------
-
- void Cappuccino::AdjustClipboardComands( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("Cappuccino","IsClipboardAcceptable");
-
- ASSERT_NOT_NULL(frame);
-
- ODBoolean hasText = !fContent->IsEmpty();
-
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandCopy, hasText);
-
- #ifndef qViewerBuild
- ODBoolean hasValidData = kODFalse;
- ODBoolean needsTranslation = kODFalse;
-
- if (!fReadOnlyStorage)
- {
- TempClipboardFocus clipboardFocus(ev, frame);
- if ( clipboardFocus.Request() )
- {
- ODClipboard* clipboard = fSession->GetClipboard(ev);
- ODStorageUnit* clipboardSU = clipboard->GetContentStorageUnit(ev);
-
- hasValidData = CCappuccinoContent::HasValidContent(ev, clipboardSU,
- &needsTranslation);
- }
- }
-
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandCut,
- !fReadOnlyStorage && hasText);
-
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandPaste,
- !fReadOnlyStorage && hasValidData);
-
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandPasteAs,
- !fReadOnlyStorage && hasValidData && needsTranslation);
-
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandClear,
- !fReadOnlyStorage && hasText);
- #else
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandCut, kODFalse);
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandPaste, kODFalse);
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandPasteAs, kODFalse);
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandClear, kODFalse);
- #endif
- }
-
- //------------------------------------------------------------------------------
- // Method: DoCut
- // Origin: Cappuccino
- //
- // Description: This method is called by the part when the user chooses the
- // Cut menu item.
- //------------------------------------------------------------------------------
-
- void Cappuccino::DoCut( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("Cappuccino","DoCut");
-
- #ifndef qViewerBuild
- ASSERT_NOT_NULL(frame);
-
- if ( !this->TryToEdit(ev, frame) )
- return;
-
- // Copy our current content to the clipboard.
- this->DoCopy(ev, frame);
-
- CCutAction* action = new CCutAction(this);
- action->Perform(ev);
- #endif
- }
-
- //------------------------------------------------------------------------------
- // Method: DoCopy
- // Origin: Cappuccino
- //
- // Description: This method is called by the part when the user chooses the
- // Copy menu item.
- //------------------------------------------------------------------------------
-
- void Cappuccino::DoCopy( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("Cappuccino","DoCopy");
-
- ASSERT_NOT_NULL(frame);
-
- TempClipboardFocus clipboardFocus(ev, frame);
- if ( clipboardFocus.Request() )
- {
- ODClipboard* clipboard = fSession->GetClipboard(ev);
- clipboard->Clear(ev);
-
- ODStorageUnit* clipboardSU = clipboard->GetContentStorageUnit(ev);
-
- TRY
- this->CloneContents(ev, clipboardSU, kODCloneCopy, frame,
- kIsForClipboard);
- CATCH_ALL
- clipboard->Clear(ev);
- RERAISE;
- ENDTRY
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: DoPaste
- // Origin: Cappuccino
- //
- // Description: This method is called by the part when the user chooses the
- // Paste menu item.
- //------------------------------------------------------------------------------
-
- void Cappuccino::DoPaste( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("Cappuccino","DoPaste");
-
- #ifndef qViewerBuild
- ASSERT_NOT_NULL(frame);
-
- if ( !this->TryToEdit(ev, frame) )
- return;
-
- TempClipboardFocus clipboardFocus(ev, frame);
- if ( clipboardFocus.Request() )
- {
- ODClipboard* clipboard = fSession->GetClipboard(ev);
- ODStorageUnit* clipboardSU = clipboard->GetContentStorageUnit(ev);
-
- // Get the new content from the clipboard's storage unit.
- CCappuccinoContent* content = new CCappuccinoContent(this);
- TempRefCounted contentTemp = content;
- content->InitCappuccinoContent(ev, clipboardSU);
-
- CPasteAction* action = new CPasteAction(this, content);
- action->Perform(ev);
- }
- #endif
- }
-
- //------------------------------------------------------------------------------
- // Method: DoPasteAs
- // Origin: Cappuccino
- //
- // Description: This method is called by the part when the user chooses the
- // Paste As... menu item.
- //------------------------------------------------------------------------------
-
- void Cappuccino::DoPasteAs( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("Cappuccino","DoPaste");
-
- #ifndef qViewerBuild
- ASSERT_NOT_NULL(frame);
-
- if ( !this->TryToEdit(ev, frame) )
- return;
-
- TempClipboardFocus clipboardFocus(ev, frame);
- if ( clipboardFocus.Request() )
- {
- ODClipboard* clipboard = fSession->GetClipboard(ev);
-
- ODPasteAsResult pasteAsResult;
- pasteAsResult.selectedKind = kODNULL;
- pasteAsResult.translateKind = kODNULL;
- pasteAsResult.editor = kODNULL;
- TempODPasteAsResult pasteAsResultTemp = &pasteAsResult;
-
- // Parameters except pasteAsResult are omitted
- if ( clipboard->ShowPasteAsDialog(ev,
- kODTrue, // canPasteLink
- kODPasteAsMergeOnly, // mergeSetting
- this->GetActiveFacetForFrame(ev, frame),
- kODNullTypeToken, // viewtype
- &pasteAsResult) )
- {
- ODStorageUnit* contentSU = clipboard->GetContentStorageUnit(ev);
-
- this->HandlePasteAsResult(ev, pasteAsResult, contentSU);
- }
- }
- #endif
- }
-
- //------------------------------------------------------------------------------
- // Method: DoClear
- // Origin: Cappuccino
- //
- // Description: This method is called by the part when the user chooses the
- // Clear menu item.
- //------------------------------------------------------------------------------
-
- void Cappuccino::DoClear( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("Cappuccino","DoClear");
-
- #ifndef qViewerBuild
- if ( !this->TryToEdit(ev, frame) )
- return;
-
- CClearAction* action = new CClearAction(this);
- action->Perform(ev);
- #endif
- }
-
-